16F87x Bootloader Quick Start

http://www.workingtex.com/htpic/

Microchip PIC 16F876/877 memory map with the bootloader installed. PIC 16F873/4
memory map is similar.

Address
0x0000  ----------------------------
		    |   Jump to bootloader     |	<--- Bootloader uses 1st 4 words (0x0000-0x0003)
0x0004  |--------------------------|
        |                          |
        |                          |
        |                          |
        |      Program space       |
        |      available for       |	<--- Available space for user programs
        |   downloaded programs    |
        |                          |
        |                          |
0x1F00  |--------------------------|
        |   Jump to user program   |	<--- 1st 4 user program words (0x1F00-0x1F03)
0x1F04  |--------------------------|
        |                          |
        |     Bootloader code      |	<--- The bootloader code (0x1F04-0x1FFF)
        |                          |
0x1FFF  ----------------------------

**************************
How to use this bootloader

1.  First, connect the serial port of your computer to the PIC micro.

The serial port operates at +/- 13V, and the PIC serial operates at +5V/0V.  Use
a MAX232, MAX3222, or SIPEX232 level shifter to connect the serial port of the
computer to pins RX/TX on PIC.  For the schematic, see the attached .gif and
Protel 99 .sch files.

You can also buy a commercial adaptor, called the PAS12 serial adaptor from the
Working Technologies website, http://www.workingtex.com/htpic, have a look under
bootloader.

You only need one serial port - ignore the M2_xx lines in the schematic as they
are not needed for a simple bootloader.

The FAQ at http://www.workingtex.com/htpic has the same schematic diagrams, plus a
troubleshooter guide for non-working serial ports.

2.	Select the correct .hex file.  You must get the crystal speed correct.
Options are 3.6864, 4, 16 and 20Mhz for the 16F873 or 16F876.  As far as
programming goes, the 16F873 is the same as the 16F874, and the 16F876 is the
same as the 16F877. For example, a 16F876, 16Mhz, downloading at 19200 baud
would be "61619 - bootldr-16F876-77-16Mhz-19200bps.hex".

3.  Recompile your code so it doesnt overwrite the bootloader.  The bootloader
uses 255 bytes at the top of ROM.  For the 16F876/7, which has 8k of ROM, this
is ROM locations 0x1F00 to 0x1FFF.  For the 16F873/4, which has 4k of ROM, this
is ROM locations 0x0F00 to 0x0FFF.

For Hi-Tech C, add -ICD to the PICC options. This reserves the top 256 bytes of
the ROM for the ICD (In-Circuit-Debugger), which means the bootloader works also.

For CCS C, add *only one* of the next two statements, depending on the micro:

#ORG 0x0F00,0x0FFF {} //for the 4k 16F873/4
#ORG 0x1F00,0x1FFF {} //for the 8k 16F876/7

For assembly, add an equivalent line reserving these program locations.

4.  New version works with a long or short jump in first 4 bytes of file.

5.  Program the target pic micro with this .hex file with a programmer such as
the PICStart Plus.

6.  Run "pic_downloader.exe", and choose 19200bps, write eeprom, and the .hex
file to download.  Again, get the crystal speed correct.  For example, for a
16Mhz crystal, choose "_19160 - test_serial_19200baud_16Mhz.hex".

Click 'write' and the windows program will begin searching for bootloader.

7.  Reset PIC micro now.  The bootloader is active for 4 seconds after reset.

8.	The test program simply prints out a single text message @ 19200 baud on
powerup, run '19200-com1.ht' to see it.  Remember to close "pic_downloader.exe"
first, because the program reserves the serial port for itself.

9.  In future, after powerup, bootloader times out in 1/2 sec and then runs the
target program normally.  Reset the PIC micro now, and you should see it pause
for 1/2 sec, then start printing serial.


(c)2001 Shane Tolmie, shane@workingtex.com
see http://www.workingtex.com/htpic for more projects like this and a huge FAQ on Hi-Tech C.

